﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Planisoft.Entities;
using Planisoft.BL;
using Microsoft.Practices.Unity;

namespace Planisoft.ClienteMvcWeb.Controllers
{
    public class PlantillaAporteController : Controller
    {
        //
        // GET: /PlantillaAporte/
        [Dependency]
        public IPlantillaAporteBL PlantillaAporteBL { get; set; }

        [Dependency]
        public IAportePdtSunatBL AportePdtSunatBL { get; set; }


        public ActionResult Index()
        {
            var lista = PlantillaAporteBL.GetAllFromPlantillaAporte();
            return View(lista);
        }

        //
        // GET: /PlantillaAporte/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /PlantillaAporte/Create

        public ActionResult Create()
        {
            var listAportePdtSunaId = AportePdtSunatBL.GetAllFromAportePdtSunat();
            ViewData["IdAportePdtSunat"] = new SelectList(listAportePdtSunaId, "IdAportePdtSunat", "DescAportSunat");

            return @PartialView("_Create");
        } 

        //
        // POST: /PlantillaAporte/Create

        [HttpPost]
        public ActionResult Create(PlantillaAporte plantillaAporte)
        {
            try
            {
                // TODO: Add insert logic here
                PlantillaAporteBL.AddPlantillaAporte(plantillaAporte);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /PlantillaAporte/Edit/5
 
        public ActionResult Edit(int id)
        {
            var plantillaAporte = PlantillaAporteBL.GetFromAporteById(id);

            var listAportePdtSunaId = AportePdtSunatBL.GetAllFromAportePdtSunat();
            ViewData["IdAportePdtSunat"] = new SelectList(listAportePdtSunaId, "IdAportePdtSunat", "DescAportSunat", plantillaAporte.IdAportePdtSunat);
            
            return @PartialView("_Edit",plantillaAporte);
        }

        //
        // POST: /PlantillaAporte/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, PlantillaAporte plantillaAporte)
        {
            try
            {
                PlantillaAporteBL.UpdatePlantillaAporte(plantillaAporte); 
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /PlantillaAporte/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /PlantillaAporte/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
